package com.xjy.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.xjy.common.utils.PageUtils;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import org.springframework.stereotype.Service;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.system.domain.bo.ReportBudgetExpendQueryBo;
import com.xjy.system.domain.ReportBudgetExpend;
import com.xjy.system.mapper.ReportBudgetExpendMapper;
import com.xjy.system.domain.vo.ReportBudgetExpendVo;
import com.xjy.system.service.IReportBudgetExpendService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 预算支出执行报告Service业务层处理
 *
 * @author mlb
 * @date 2022-03-08
 */
@Service
public class ReportBudgetExpendServiceImpl extends ServicePlusImpl<ReportBudgetExpendMapper, ReportBudgetExpend> implements IReportBudgetExpendService {

    @Override
    public ReportBudgetExpendVo queryById(Long subjectId){
        return getVoById(subjectId, ReportBudgetExpendVo.class);
    }

    @Override
    public TableDataInfo<ReportBudgetExpendVo> queryPageList(ReportBudgetExpendQueryBo bo) {
        PagePlus<ReportBudgetExpend, ReportBudgetExpendVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ReportBudgetExpendVo.class);
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<ReportBudgetExpendVo> queryList(ReportBudgetExpendQueryBo bo) {
        return listVo(buildQueryWrapper(bo), ReportBudgetExpendVo.class);
    }

    private LambdaQueryWrapper<ReportBudgetExpend> buildQueryWrapper(ReportBudgetExpendQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportBudgetExpend> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getSubjectId() != null, ReportBudgetExpend::getSubjectId, bo.getSubjectId());
        lqw.like(StrUtil.isNotBlank(bo.getSubjectName()), ReportBudgetExpend::getSubjectName, bo.getSubjectName());
        lqw.eq(bo.getProjId() != null, ReportBudgetExpend::getProjId, bo.getProjId());
        return lqw;
    }

}
